package com.spring.cardapi.web.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.codehaus.jackson.map.util.JSONPObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.common.collect.Maps;
//import com.spring.iosservice.web.service.IosQuestService;
import com.spring.cardapi.web.service.CardApiService;
import com.spring.security.core.util.ApplicationUtils;
import com.spring.security.web.dao.JedisCache;

@Controller
@RequestMapping(value = "/cardApi")
public class CardApiController {

	@Resource
	private CardApiService cardApiService;
	
	@Resource private JedisCache jedisCache;
	
	@ResponseBody
    @RequestMapping(value="/getTest", method = RequestMethod.GET)
    public Object getTest(HttpServletRequest request,HttpServletResponse response) throws Exception{
		Map<String,Object> m = Maps.newHashMap();
		m.put("1111", "22222");
		jedisCache.set("aa", "aaa");
		System.out.println(jedisCache.get("aa"));
        return m;
    }

	// 查看自己消费记录
	@RequestMapping(value = "/getOrderList")
	@ResponseBody
	public Object getOrderList(String token, String orderID, String rechargecardID, String membercardID,
			String page_size, String page_index, String skip, String rows, String callback) {

		Map<String, Object> m = new HashMap<String, Object>();
		try {
			m = cardApiService.getOrderList(token, orderID, rechargecardID, membercardID, page_size, page_index, skip,
					rows);
		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}

	// 查看自己消费记录
	@RequestMapping(value = "/getConsumeList")
	@ResponseBody
	public Object getCardTypeList(String token, String card_id, String page_size, String page_index, String skip,
			String rows, String callback) {

		Map<String, Object> m = new HashMap<String, Object>();
		try {
			m = cardApiService.getConsumeList(token, card_id, page_size, page_index, skip, rows);
		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}

	@RequestMapping(value = "/getPointBillList")
	@ResponseBody
	public Object getPointBillList(String token, String page_size, String page_index, String skip, String rows,
			String callback) {
		Map<String, Object> m = new HashMap<String, Object>();
		try {
			m = cardApiService.getPointBillList(token, page_size, page_index, skip, rows);
		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}

	@RequestMapping(value = "/createCouponCode")
	@ResponseBody
	public Object createCouponCode(String token, String callback) {

		Map<String, Object> m = new HashMap<String, Object>();
		try {
			m = cardApiService.createCouponCode(token);
		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}

	@RequestMapping(value = "/getMyCouponList")
	@ResponseBody
	public Object getMyCouponList(String token, String isused, String callback) {
		Map<String, Object> m = new HashMap<String, Object>();
		try {
			m = cardApiService.getMyCouponList(token, isused);
		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}

}
